﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net;
using System.Web;
using System.Windows.Forms;
using Microsoft.SharePoint.Administration;
using Wagner.Utilities;

namespace Wagner.SharePoint.Utilities
{
	internal class RecycleAppPool : OperationBase
	{
		internal RecycleAppPool()
		{}

		internal override void Run()
		{
			string url = ValidateParameter("url", true, null);
			
			// Recycle the application pool for the web application url.
			Console.Write("Recycling the application pool ");
			SPApplicationPool appPool = IISUtilities.GetApplicationPool(url);
			Console.WriteLine(string.Format("'{0}'.", appPool.DisplayName));
			IISUtilities.RecycleApplicationPool(appPool.DisplayName);
		}

		internal override string HelpSummary
		{
			get
			{
				return @"
-o RecycleAppPool 
     Recycles the IIS application pool using the web application URL instead
     of requiring the application pool name, which can also be different among
     different developer machines.";
			}
		}

		internal override string HelpDetail
		{
			get
			{
				string help = HelpSummary + @"
Usage:
  SPDev.exe -o RecycleAppPool -url <url>

    Parameters: 
     -url <web server url>
       Specifies the url of the SharePoint web application on the local machine
       whose IIS application pool is to be recycled.
     
Examples:
 SPDev.exe -o RecycleAppPool -url http://localhost
 SPDev.exe -o RecycleAppPool -url http://MySharePointSite

";

				return help;
			}
		}

	}	
}
